home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / PEEKLAST.ASM < prev    next >
Assembly Source File  |  1992-03-05  |  2KB  |  96 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.  
  6.  
  7. wp        equ    <word ptr>        ;I'm a lazy typist
  8.  
  9.  
  10. ; Special case to handle MASM 6.0 vs. all other assemblers:
  11. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  12.  
  13.         ifndef    @version
  14. @version    equ    500
  15.         endif
  16.  
  17.  
  18.  
  19. StdGrp        group    stdlib,stddata
  20. stddata        segment    para public 'sldata'
  21. stddata        ends
  22.  
  23. stdlib        segment    para public 'slcode'
  24.         assume    cs:stdgrp
  25.  
  26. ; sl_PeekLast -    ES:DI points at a list.
  27. ;        Returns a pointer to the last item in the list in DX:SI.
  28. ;        Returns the carry flag set if the list was empty.
  29. ;
  30. ; Randall Hyde  3/3/92
  31. ;
  32.  
  33.         public    sl_PeekLast
  34. sl_PeekLast    proc    far
  35.  
  36.         if    @version ge 600
  37.  
  38. ; MASM 6.0 version goes here
  39.  
  40.         cmp    wp es:[di].List.Tail+2, 0    ;Empty list?
  41.         jne    HasAList
  42.  
  43. ; At this point, the Head pointer is zero.  This only occurs if the
  44. ; list is empty.
  45. ;
  46. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  47. ; package assumes that if the segment is zero, the whole thing is zero.
  48. ; So don't put any nodes into segment zero!
  49.  
  50.         xor    dx, dx                ;Set DX:SI to NIL.
  51.         mov    si, dx
  52.         stc
  53.         jmp    PeekDone
  54.  
  55. ; If the Tail pointer is non-NIL, return a pointer to the last node in the
  56. ; list.
  57.  
  58. HasAList:    mov    si, wp es:[di].List.Tail      ;Get ptr to first
  59.         mov    dx, wp es:[di].List.Tail+2    ; item
  60.  
  61.  
  62.         else
  63.  
  64. ; All other assemblers come down here:
  65.  
  66.         cmp    wp es:[di].Tail+2, 0        ;Empty list?
  67.         jne    HasAList
  68.  
  69. ; At this point, the Head pointer is zero.  This only occurs if the
  70. ; list is empty.
  71. ;
  72. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  73. ; package assumes that if the segment is zero, the whole thing is zero.
  74. ; So don't put any nodes into segment zero!
  75.  
  76.         xor    dx, dx                ;Set DX:SI to NIL.
  77.         mov    si, dx
  78.         stc
  79.         jmp    PeekDone
  80.  
  81. ; If the Tail pointer is non-NIL, return Tail down here.
  82.  
  83. HasAList:    mov    si, wp es:[di].Tail          ;Get ptr to first
  84.         mov    dx, wp es:[di].Tail+2        ; item
  85.  
  86.  
  87.         endif
  88.  
  89.         clc
  90. PeekDone:    ret
  91.  
  92. sl_PeekLast    endp
  93.  
  94. stdlib        ends
  95.         end
  96.